package com.darth.common.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.darth.common.enums.ENUM_RESULT;
import com.darth.common.exception.dto.common.Status;
/**
 * 
 * 公用方法
 * 
 * @author James·Von·LeeBoom  
 * @date 2017年6月14日 下午4:33:13
 * @version V1.0
 */
public class CommonUtil {

    /**
     * 
     * 封装Status信息
     * @param statuscode 01/02/03/200/500
     * @param succ Y/N
     * @param msgs 
     * @return
     * @throws Exception
     */
    public static Status setStatus(String statuscode,String succ,String... msgs) {      
        List<String> msgList=new ArrayList<>();
        if(msgs.length!=0)           msgList=Arrays.asList(msgs);
        else            msgList.add("");        
        return setStatus(statuscode, succ, msgList);
    }
    
    /**
     * 
     * 封装Status信息
     * @param statuscode 01/02/03/200/500
     * @param succ Y/N
     * @param msgList 
     * @return
     * @throws Exception
     */
    public static Status setStatus(String statuscode,String succ,List<String> msgList) {
        Status status=new Status();
        status.setStatuscode(statuscode);
        status.setSuccess(succ);
        status.setStatusmessage(msgList);
        return status;
    }
    /**
     * 
     * 封装Status信息
     * @param statuscode 状态码
     * @param 封装信息
     * @return
     */
    public static Status setPolicyStatus(String statuscode,String msg) {
        Status status=new Status();
        if (ENUM_RESULT.SUCCESS.code().equals(statuscode)) {
            statuscode="200";
        } else if (ENUM_RESULT.FAIL.code().equals(statuscode) ||  ENUM_RESULT.UNUSUAL.code().equals(statuscode)) {
            statuscode="404";
        }
        List<String> msgList=new ArrayList<>();
        if(msg.length()!=0){
            msgList=Arrays.asList(msg);
        }else{
            msgList.add("");
        }
        status.setStatuscode(statuscode);
        status.setStatusmessage(msgList);
        return status;
    }
    /**
     * 
     * 调用核心url
     * 
     * @param requestUrl
     *            请求地址
     * @param requestUrl
     *            请求信息
     * @return String
     */
    @SuppressWarnings("static-access")
    public static String invokeUrl(String requestUrl, String requestData) {
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        return httpClientUtil.request(requestUrl, requestData);
    }

}
